<script>
//app.js
var setting = require("./setting.js");
var auth = require("./utils/auth.js");
var request = require("./utils/request.js");
var common = require("./utils/common.js");


export default {
  globalData: {
    setting: setting,
    //用户可配置项
    wechatUser: null,
    //微信的用户信息
    userInfo: null,
    //商城的用户信息TP 
    config: null,
    //app系统配置
    code: null,
    //微信登录code
    menu_index: 0,
    //自定义菜单索引
    menu_model: [],
    //自定义菜单模型
    defaultMenu: false,
    //自定义菜单状态  
    is_apply: 0,
    //是否在审核阶段
    constom_index: null //自定义首页数据本地调用
    ,

    /** 授权对象 */
    auth: auth,

    /** 全局请求对象，涉及业务的请求，请使用此接口 */
    request: request,
    initExt: function () {
      var ext = uni.getExtConfigSync ? uni.getExtConfigSync() : {}
      var setting = this.setting;

      if (ext.store_name) {
        setting.appName = ext.store_name;
        setting.share.title = ext.store_name;
        setting.appLogo = ext.store_logo;
        setting.saas_app = ext.saas_app;

        if (ext.is_refactor) {
          setting.url = ext.request_url + '/saas/' + setting.saas_app;
        } else {
          setting.url = ext.request_url;
        }

        setting.ext_on = 1; //第三方配置开启
      } else {
        setting.saas_app = '';
        setting.ext_on = 0;
      }
    },

    /** 
     * 获取用户信息（包括微信用户），有授权作用
     * cb：成功回调函数，入参:cb(userInfo,wechatUser)
     * force：是否强制更新数据（发出请求）
     */
    getUserInfo: function (cb, force, isShowLoading) {
      var that = this;

      if (auth.isAuth() && !force) {
        typeof cb == "function" && cb(that.userInfo, that.wechatUser);
      } else {
        if (!auth.isAuth()) {
          return auth.auth(cb); //授权操作
        }

        request.get('/api/user/userInfo', {
          isShowLoading: typeof isShowLoading == 'undefined' ? true : isShowLoading,
          success: function (res) {
            if (res.data.result.head_pic) {
              if (res.data.result.head_pic.indexOf("http") == -1) {
                res.data.result.head_pic = setting.url + res.data.result.head_pic;
              }
            }

            uni.setStorageSync('app:userInfo', res.data.result);
            that.userInfo = res.data.result;
            that.userInfo.head_pic = common.getFullUrl(that.userInfo.head_pic);
            typeof cb == "function" && cb(that.userInfo, that.wechatUser);
          }
        });
      }
    },

    /** 获取app系统配置 */
    getConfig: function (cb, force) {
      var that = this;

      if (this.config && !force) {
        typeof cb == "function" && cb(this.config);
      } else {
        request.get('/api/index/getConfig', {
          success: function (res) {
            that.config = res.data.result;
            typeof cb == "function" && cb(that.config);
          }
        });
      }
    },

    /** 获取前index页的数据，默认前一页 */
    getPrevPageData: function (index) {
      if (typeof index == 'undefined') {
        index = 1;
      }

      var pages = getCurrentPages();
      return pages[pages.length - index - 1].data;
    },

    /** 加载提醒 */
    showLoading: function (func, time) {
      typeof time == 'undefined' && (time = 1500);
      uni.showToast({
        title: '加载中',
        icon: 'loading',
        duration: time,
        mask: true,
        complete: function () {
          if (typeof func == 'function') {
            setTimeout(func, time);
          }
        }
      });
    },
    showSuccess: function (msg, func, time) {
      typeof time == 'undefined' && (time = 1000);
      uni.showToast({
        title: msg,
        icon: 'success',
        duration: time,
        mask: true,
        complete: function () {
          if (typeof func == 'function') {
            setTimeout(func, time);
          }
        }
      });
    },
    showWarning: function (msg, func, time, mask) {
      !time && (time = 1500);
      typeof mask == 'undefined' && (mask = true);
      uni.showToast({
        title: msg,
        mask: mask,
        duration: time,
        image: "/static/images/gt.png",
        complete: function () {
          if (typeof func == 'function') {
            setTimeout(func, time);
          }
        }
      });
    },
    showTextWarining: function (msg, func, time, mask) {
      !time && (time = 2000);
      typeof mask == 'undefined' && (mask = true);
      uni.showToast({
        title: msg,
        mask: mask,
        duration: time,
        icon: 'none',
        complete: function () {
          if (typeof func == 'function') {
            setTimeout(func, time);
          }
        }
      });
    },
    confirmBox: function (msg, func) {
      uni.showModal({
        title: msg,
        showCancel: false,
        complete: function () {
          typeof func == 'function' && func();
        }
      });
    },
    validatemobile: function (mobile) {
      if (mobile.length == 0) {
        this.showTextWarining('请输入手机号码!');
        return false;
      }

      if (mobile.length != 11) {
        this.showTextWarining('手机号码长度有误!');
        return false;
      }

      var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;

      if (!myreg.test(mobile)) {
        this.showTextWarining('手机号码有误!');
        return false;
      }

      return true;
    },

    hidetabbar() {
      //隐藏默认tab
      uni.hideTabBar({
        fail: function () {
          setTimeout(function () {
            // 做了个延时重试一次，作为保底。
            uni.hideTabBar();
          }, 500);
        }
      });
    }

  },

  /** 启动加载 */
  onLaunch: function () {
    this.globalData.hidetabbar();
    this.globalData.initExt();
    var setting = this.globalData.setting;
    setting.resourceUrl = setting.url + '/template/mobile/rainbow';
  },
  methods: {}
};
</script>
<style>
/** 自定义菜单样式 */
@import "./pages/index/publics/publics.scss";
/**app.wxss**/
.flex {
  display: flex;
}
.flex-center {
  display: flex;
  align-items: center;
}
.flex_auto {
  flex: 1;
}
.container {
    font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    padding-bottom:134rpx;
    width: 100%;
    overflow-x: hidden;
}
page {
    background-color: #f5f5f5;
}
button{
    border-radius: 0;
    padding-left: 0;
    padding-right: 0;
    background-color:transparent;
    font-size: 28rpx;
}
.wh100{
    width: 100%;
    height: 100%;
}
/* 
    单行文本超出隐藏,
    要使用的div必须要有宽和高
 */
.ellipsis-1{   
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
/* 
    两行文本超出隐藏,
    要使用的div必须要有宽和高
 */
.ellipsis-2{
    overflow:hidden; 
    text-overflow:ellipsis;
    display:-webkit-box; 
    -webkit-box-orient:vertical;
    -webkit-line-clamp:2;
}
.pd-bg-fff{
    padding: 0 20rpx;
    /* background-color: #fff;
    font-size:32rpx;
    width:710rpx;
    box-sizing: border-box;
    margin: 0 auto;
    margin-top: 20rpx;
    border-radius: 10rpx; */
}
.co-red{
    color: #ff6a00;
}
.hide{
    display: none;
}
.t-c{
    text-align: center;
}
/* 掩盖层 */
.cover-layer{
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    background: rgba(0,0,0,0.4);
    width: 100%;
    height: 100%;
}
/* 弹框的关闭按钮 */
.modal-close{
    position: absolute;
    right: 25rpx;
    top: 25rpx;
}
/* 空白页 */
.no-data{
    width: 100%;
    text-align: center;
    margin-bottom: 45rpx;
}
.no-data .no-data-title{
    color: #9b9b9b;
    margin-bottom: 30rpx;
    font-size: 30rpx;
}
.no-data .cart-image {
    width: 140px;
    height: 140px;
    margin-top: 100rpx;
}
.no-data .lookat{
    padding: 0rpx 40rpx;
    background-color: white;
    display: inline-block;
    border-radius: 10rpx;
    margin: 0 auto;
    font-size: 30rpx;
    color: #333;
    height: 80rpx;
    line-height: 80rpx;
}

.red-on{
  color: #ff6a00;
  font-weight: bold;
}

.little-btn-1 {
  width: 150rpx;
  height: 48rpx;
  line-height: 48rpx;
  text-align: center;
  margin-left: 20rpx;
  border-radius: 5rpx;
  background: #ff6a00;
  color: #fff;
  font-size: 24rpx;
  border: 1rpx solid #ff6a00;
  box-sizing: border-box;
  display: inline-block;
}

.little-btn-2 {
  width: 150rpx;
  height: 48rpx;
  line-height: 48rpx;
  text-align: center;
  margin-left: 20rpx;
  border-radius: 5rpx;
  background: #fff;
  color: #999999;
  font-size: 24rpx;
  border: 1rpx solid #E6E6E6;
  box-sizing: border-box;
  display: inline-block;
}
.choosebox{
  width: 40rpx;
  height: 40rpx;
  display: inline-block;
}
.choosebox image{
  width: 100%;
  height: 100%;
  display: block;
}
.bacf5{
  background: #f5f5f5;
}
.ml10{
  margin-left: 10rpx;
}
.mr10{
  margin-right: 10rpx;
}
.ml20{
  margin-left: 20rpx;
}
.mr20{
  margin-right: 20rpx;
}
.mr30{
  margin-right: 30rpx;
}
.mt20{
  margin-top: 20rpx;
}
.mt30{
  margin-top: 20rpx;
}
.ml30{
  margin-left: 30rpx;
}

.border-r10{
  border-radius:10rpx; 
}
/* 删除线 */
.text-decoration{
  text-decoration:line-through;
}
  /* 去掉滚动条 */
.scroll-no::-webkit-scrollbar{
	display: none;
  width: 0;
  height: 0;
  color: transparent;
}
/* 模态框-s */
.bind-content{
  width: 610rpx;
  height: 360rpx;
  background: rgba(255,255,255,1);
  border-radius: 20rpx;
  margin-left: 70rpx;
  margin-top: calc(50vh - 180rpx);
}
.bind-content .bind-tit{
  width: 460rpx;
  font-size: 30rpx;
  color: #333;
  padding: 70rpx 76rpx;
  line-height: 60rpx;
  text-align: Center;
}
.bind-content .bind-operation{
  display: flex;
  border-top: 2rpx solid #E6E6E6;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  font-size: 30rpx;
}
.bind-content .bind-operation view{
  width: 304rpx;
  color: #999;
  border-right:2rpx solid #E6E6E6;
}
.bind-content .bind-operation .btn{
  width: 304rpx;
  color: #26C023;
  line-height: 100rpx;
}
.bind-content .bind-operation .btn::after{
  border: none;
}
/* 模态框-e */
</style>